package xian.woniuxy.f_equals;

class Person {
    private int id;
    private String name;

    public Person() {

    }

    public Person(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof Person)) {
            return false;
        }
        Person that = (Person) obj;
        return this.id == that.id && this.name.equals(that.name);
    }
}

public class App {
    public static void main(String[] args) {
        Person p = new Person(1, "andy");
        Person p2 = new Person(1, "andy");

        System.out.println(p.equals(p2));  // 虚方法调用 后期绑定  运行时决定。
    }
}
